1
'****************************** Module Header ******************************'
2 ' Module Name: Converters.vb
3 ' Project: VBWPFDataBinding
4 ' Copyright (c) Microsoft Corporation.
6 ' This example demonstrates how to use DataBinding in WPF
8 ' This source is subject to the Microsoft Public License.
9 ' See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
10 ' All other rights reserved.
12 ' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
13 ' EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
14 ' WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
15 '***************************************************************************'
17 Public Class SalaryFormmatingConverter
18 Implements IValueConverter
20 #Region
"IValueConverter Members"
22 Public Function Convert(ByVal value
As Object, ByVal targetType
As Type, ByVal parameter
As Object, ByVal culture
As System
.Globalization
.CultureInfo
) As Object Implements IValueConverter
.Convert
23 Dim dolloars
As Double = 0
24 Dim formattedSalary
As String = String.Empty
26 If value Is
Nothing Then
27 Throw
New NullReferenceException("value can not be null")
29 [Double].TryParse(value
.ToString(), dolloars
)
31 formattedSalary
= [String].Format("Total={0}$", dolloars)
32 Return formattedSalary
35 Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
36 Dim dolloars As Double = 0
37 If value Is Nothing Then
38 Throw New NullReferenceException("value can
not be null
")
40 [Double].TryParse(value.ToString().TrimStart(New Char() {"T
"c, "t
"c, "o
"c, "a
"c, "l
"c, "="c}).TrimEnd("$"c), dolloars
)